<template>
  <view v-for="(item,index) in data.list" class="u-m-20 manage-item" :key="index">
    <view class="u-flex-y-center u-flex-between">
      <u-text :text="item.createtime" color="#888" size="12"></u-text>
      <u-text text="已发布" color="#E47117" size="14" align="right"></u-text>
    </view>
    <house-item :item="item" customStyle="background:#fff;margin:0;padding:0" :imageWidth="234" imageHeight="192">
      <template #right>
        <view class="u-flex-between u-flex-column u-flex-fill">
          <view class="house-name">
            {{item.title}}
          </view>
          <view class="house-desc" v-if="item.description">“{{item.description}}”</view>
          <view class="house-info">“{{item.space}}㎡ | {{item.house_type_text}} | {{item.space}}”</view>
          <view class="house-price u-flex-y-center u-flex-between">
            <text>市场价：{{item.market_price}}万</text>
            <text >优惠价：{{item.price}}万</text>
          </view>
        </view>
      </template>
    </house-item>
    <view class="manage-action u-m-t-20 u-flex-y-center u-flex-between">
      <u-image src="/static/images/04_17ng.png" :fade="false" width="224rpx" height="54rpx"></u-image>
      <view class="">
        <text class="u-m-r-40" @click="handleHb(item)">每日红包</text>
        <text class="u-m-r-40" @click="$u.route(`/pages/houseMine/houseManage/addHouse?id=${item.id}`)">编辑</text>
        <text @click="_house_del(item)">删除</text>
      </view>
    </view>
  </view>
  <view class="action-btn"  @click="$u.route('/pages/houseMine/houseManage/addHouse')">新增房源</view>
</template>

<script setup>
  import { house_del, house_lst } from '../../../config/api';
  import houseItem from '@/components/house-item/house-item.vue';
  import { onShow, onReachBottom } from '@dcloudio/uni-app'
  import { nextTick, ref } from 'vue';

  const params = ref({
    page: 1,
    limit: 15
  })
  const data = ref({
    list: []
  })
  onShow(() => {
    _house_lst()
  })
  onReachBottom(() => {
    params.value.page++
    _house_lst()
  })
  // 红包
  const handleHb = (item) => {
    uni.$u.route(`/pages/houseMine/houseManage/houseReward?id=${item.id}`,item)

  }
  // 删除房源
  const _house_del = (item) => {
    uni.showModal({
      content: '确定删除该房源吗',
      success: (res) => {
        if (res.confirm) {
          house_del({ id: item.id }).then(res => {
            uni.$u.toast(res.msg)
            _house_lst()
          })
        }
      }
    })
  }
  // 房源列表
  const _house_lst = () => {
    house_lst(params.value).then(res => {
      if (params.value.page == 1) data.value.list = res.data.data
      else data.value.list = data.value.list.concat(res.data.data)
    })
  }
</script>

<style scoped lang="scss">
  .manage-item {
    background: #fff;
    padding: 20rpx;
    border-radius: 16rpx;

    .manage-action {
      color: #F24C1E;
      font-size: 30rpx;
      font-weight: 800;
      border-top: 1px solid #eee;
      padding-top: 12rpx;
    }
  }

  .house-name {
    font-size: 26rpx;
    color: #333;
    font-weight: 800;
  }

  .house-info {
    font-size: 24rpx;
    font-weight: 500;
    color: #666;
  }

  .house-desc {
    font-size: 22rpx;
    color: #E47117;
  }

  .house-price {
    color: #DF0F0F;
    font-weight: 800;
    font-size: 24rpx;
  }

  .action-btn {
    background: #F87610;
    border-radius: 50rpx;
    text-align: center;
    line-height: 90rpx;
    font-size: 30rpx;
    color: #fff;
    position: fixed;
    bottom: env(safe-area-inset-bottom);
    left: 30rpx;
    right: 30rpx;
  }
</style>